﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Data;

namespace Demo05.Controls
{
    class ListBoxMap: ListBox
    {
        protected override void PrepareContainerForItemOverride(Windows.UI.Xaml.DependencyObject element, object item)
        {
            var i = item as Models.Item;
            var l = element as ListBoxItem;

            var yBinding = new Binding { Path = new PropertyPath("Y"), Source = i };
            l.SetBinding(Canvas.TopProperty, yBinding);

            var xBinding = new Binding { Path = new PropertyPath("X"), Source = i };
            l.SetBinding(Canvas.LeftProperty, xBinding);

            base.PrepareContainerForItemOverride(element, item);
        }
    }
}
